package components.dialogs.adjustments
{
	import UIFree.uif_component;
	
	import classes.Commands.c_applyColorTransform;
	
	import components.dialogs.c_elementPropDlg;
	import components.dialogs.c_propertyDialog;
	import components.editor.c_baseElement;
	
	import flash.geom.ColorTransform;
	
	public class c_RGBBalance extends c_elementPropDlg {
		private var _safeMatrix: ColorTransform;
		
		public function c_RGBBalance(parent:uif_component, a_element:c_baseElement, a_title:String='', modal:Boolean=false, canClose:int=2) {
			_safeMatrix	= new ColorTransform();
			_safeMatrix.concat(a_element.transform.colorTransform);
			
			super(parent, a_element, [{
				title	: 'Цветовой баланс',
				type	: c_propertyDialog.PTYPE_COLORBALANCE,
				value	: {
					red		: 0,
					green	: 0,
					blue	: 0
				}
			}], a_title, modal, canClose);
		}
		
		override protected function updateElement(): void {
			var ct: ColorTransform = new ColorTransform();
			ct.concat(_safeMatrix);
			ct.concat(matrix);
			element.transform.colorTransform = ct;
		}
		
		protected function get matrix(): ColorTransform {			
			return new ColorTransform(
				1,
				1,
				1,
				1,
				values[0].value.red  * 0xFF,
				values[0].value.green * 0xFF,
				values[0].value.blue * 0xFF
			); 
		}
		
		override protected function doCancel():void {
			element.transform.colorTransform = _safeMatrix;
		}
		
		override protected function doApply():void {
			element.transform.colorTransform = _safeMatrix;
			executeCommand(new c_applyColorTransform(element, matrix));
		}
	}
}